//
//  ZH_GoodsInfoTableViewCell.m
//  ChangeMerchants
//
//  Created by zhangliwen on 2018/9/28.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_GoodsInfoTableViewCell.h"
@interface ZH_GoodsInfoTableViewCell()
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UIButton *rightButton;
@property (nonatomic,weak)UIButton *priceButton;
@property (nonatomic,weak)UILabel *category;
@property (nonatomic,weak)UIView *lineView;
@property (nonatomic,weak)UILabel *buttomLabel;
@property (nonatomic,weak)UILabel *leftLabel;
@property (nonatomic,weak)UIImageView *rightImage;
@property (nonatomic,weak)UIButton *bottomButton;
@end
@implementation ZH_GoodsInfoTableViewCell

///创建
+ (instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_GoodsInfoTableViewCell";
    ZH_GoodsInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_GoodsInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
    
}
- (void)loadSubviewConstraints{
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(13));
        make.left.equalTo(self.contentView).offset(FITSCALE(22));
    }];
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(7));
        make.right.equalTo(self.contentView).offset(FITSCALE(-12));
        make.width.mas_equalTo(FITSCALE(71));
        make.height.mas_equalTo(FITSCALE(25));
    }];
    [self.priceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(15));
        make.left.equalTo(self.titleLabel);
        make.width.mas_equalTo(FITSCALE(68));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.category mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.priceButton);
        make.right.equalTo(self.contentView).offset(FITSCALE(-22));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.priceButton.mas_bottom).offset(FITSCALE(9));
        make.left.equalTo(self.contentView).offset(FITSCALE(11));
        make.right.equalTo(self.contentView).offset(FITSCALE(-11));
        make.height.mas_equalTo(FITSCALE(1));
    }];
    [self.buttomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(FITSCALE(10));
        make.left.equalTo(self.contentView).offset(FITSCALE(22));
        make.right.equalTo(self.contentView).offset(FITSCALE(-22));
    }];
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(self.buttomLabel.mas_bottom).offset(FITSCALE(15));
       make.left.equalTo(self.contentView).offset(FITSCALE(22));
       make.bottom.equalTo(self.contentView).offset(FITSCALE(-16));
    }];
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.leftLabel);
        make.right.equalTo(self.contentView).offset(FITSCALE(-22));
    }];
    [self.bottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.leftLabel);
        make.left.right.bottom.equalTo(self.contentView);
    }];
}
- (void)updateUI:(NSDictionary *)dic{
    if (dic) {
        self.titleLabel.text = [NSString stringWithFormat:@"%@",dic[@"goods"][@"name"]];
        self.category.text = [NSString stringWithFormat:@"分类:%@",dic[@"goods"][@"cate_name"]];
        [self.priceButton setTitle:[NSString stringWithFormat:@"%@",dic[@"goods"][@"show_price"]]];
        self.buttomLabel.text = [NSString stringWithFormat:@"运费: %@元     上架时间:%@",dic[@"goods"][@"sale_num"],dic[@"goods"][@"up_time"]];
    }
}
- (void)button:(UIButton *)btn{
    if (self.onButtonClick) {
        self.onButtonClick();
    }
}
#pragma mark - setter,getter
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"商品名称" font:kFontSize_28];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UIButton *)rightButton{
    if (!_rightButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"代理产品" target:self action:nil];
        [button setTitleColor:[UIColor colorWithHexString:@"#F0302F"] forState:UIControlStateNormal];
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#F0302F"].CGColor;
        [self.contentView addSubview:_rightButton = button];
    }
    return _rightButton;
}
- (UIButton *)priceButton{
    if (!_priceButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"商品价格" target:self action:nil];
        button.backgroundColor = kFontColorRed;
        [button setTitleColor:kFontColorWhite forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.masksToBounds = YES;
        [self.contentView addSubview:_priceButton = button];
    }
    return _priceButton;
}
- (UILabel *)category{
    if (!_category) {
        UILabel *label = [UILabel createLabelWithText:@"分类: 化妆品" font:kFontSize_26];
        label.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_category = label];
    }
    return _category;
}
- (UIView *)lineView{
    if (!_lineView) {
        UIView *lineView = [UIView createViewWithBackgroundColor:[UIColor colorWithHexString:@"#DFDFDF"]];
        [self.contentView addSubview:_lineView = lineView];
    }
    return _lineView;
}
- (UILabel *)buttomLabel{
    if (!_buttomLabel) {
        UILabel *label = [UILabel createLabelWithText:@"运费: 10元    销量: 45    库存: 12   上架时间: 2018-08-29" font:kFontSize_24];
        label.textColor = [UIColor colorWithHexString:@"#999999"];
        [self.contentView addSubview:_buttomLabel = label];
    }
    return _buttomLabel;
}
- (UILabel *)leftLabel{
    if (!_leftLabel) {
        UILabel *label = [UILabel createLabelWithText:@"商品规格" font:kFontSize_28];
        [self.contentView addSubview:_leftLabel = label];
    }
    return _leftLabel;
}
- (UIImageView *)rightImage{
    if (!_rightImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@"icon_mygetmore1"];
        [self.contentView addSubview:_rightImage = image];
    }
    return _rightImage;
}
- (UIButton *)bottomButton{
    if (!_bottomButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"" target:self action:@selector(button:)];
        button.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:_bottomButton = button];
    }
    return _bottomButton;
}
@end
